package flc.ast.activity;

import android.graphics.Color;
import android.os.Handler;
import android.view.View;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import flc.ast.BaseAc;
import flc.ast.HomeActivity;
import flc.ast.R;
import flc.ast.databinding.ActivityCompressBinding;
import stark.common.basic.event.EventStatProxy;

public class CompressActivity extends BaseAc<ActivityCompressBinding> {

    public static boolean isSingle;
    public static String imgPath;
    public static List<String> listPath = new ArrayList<>();


    @Override
    protected int onCreate() {
        return R.layout.activity_compress;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivCompressBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvAgainCompress.setOnClickListener(this);
        mDataBinding.tvComplete.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvAgainCompress://继续压缩
                finish();
                break;
            case R.id.tvComplete://完成
                startActivity(HomeActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        if (isSingle) {
            Glide.with(mContext).load(imgPath).into(mDataBinding.ivCompressImg);
            mDataBinding.tvCompressProgress.setVisibility(View.GONE);
        } else {
            mDataBinding.tvCompressProgress.setVisibility(View.VISIBLE);
            Glide.with(mContext).load(listPath.get(0)).into(mDataBinding.ivCompressImg);
            Random random = new Random();
            int index = random.nextInt(listPath.size());
            mDataBinding.tvCompressProgress.setText(index + "/" + listPath.size());
            mDataBinding.tvCompressProgress.setVisibility(View.VISIBLE);
        }
        Random random = new Random();
        int progress = random.nextInt(51);
        mDataBinding.sbProgress.setProgress(progress);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mDataBinding.sbProgress.setProgress(100);
                mDataBinding.tvCompressTip.setText(getString(R.string.compress_suc));
                mDataBinding.tvCompressTip.setTextColor(Color.parseColor("#4E70EF"));
                mDataBinding.tvCompressProgress.setText(listPath.size() + "/" + listPath.size());
                mDataBinding.tvAgainCompress.setVisibility(View.VISIBLE);
                mDataBinding.tvComplete.setVisibility(View.VISIBLE);
            }
        }, 500);
    }
}